package edu.ynu.se.xiecheng.achitectureclass.project.service;

import edu.ynu.se.xiecheng.achitectureclass.common.service.LogicService;
import edu.ynu.se.xiecheng.achitectureclass.project.dao.UserDAO;
import edu.ynu.se.xiecheng.achitectureclass.project.po.entity.User;
import org.springframework.stereotype.Service;

@Service
public class UserService extends LogicService<UserDAO, User, Long> {
    public UserService(UserDAO lr) {
        super(lr);
    }

    public User validateUser(String username, String password) {
        User user = dao.findByUsername(username);
        if (user != null && password.equals(user.getPassword())) {
            return user;
        }
        return null;
    }

    public boolean existsByUsername(String username) {
        return dao.findByUsername(username) != null;
    }

    public User save(User user) {
        return dao.save(user);
    }
}
